package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.RemoteDestinationService;
import cn.wolfcode.wolf2w.business.api.domain.Destination;
import cn.wolfcode.wolf2w.business.api.domain.DestinationEs;
import cn.wolfcode.wolf2w.business.repository.DestinationEsRepository;
import cn.wolfcode.wolf2w.business.service.IDestinationEsService;
import cn.wolfcode.wolf2w.common.core.domain.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DestinationEsServiceImpl implements IDestinationEsService {

    @Autowired
    private DestinationEsRepository repository;

    @Autowired
    private RemoteDestinationService remoteDestinationService;

    @Override
    public void initDestinationEs() {
        //发送请求到攻略服务器请求攻略数据
        R<List<Destination>> r = remoteDestinationService.list("inner");
        List<Destination> destinationList = r.getData();
        for (Destination destination : destinationList) {
            DestinationEs es = new DestinationEs();
            //属性拷贝 把同名属性拷贝到新对象中
            BeanUtils.copyProperties(destination,es);
            repository.save(es);
        }
        //将攻略数据转换为Es数据的类型

        //存储到Es库中
    }
}
